package com.engine4cloud.tdf.supervision.controller.web;

import com.engine4cloud.tdf.common.core.constant.enums.*;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.supervision.dto.query.SpAuditResultQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.EnumsTypeResultDTO;
import com.engine4cloud.tdf.supervision.dto.result.SpAuditResultDTO;
import com.engine4cloud.tdf.supervision.service.SpAuditResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 审批-全部流程-web
 *
 * @author wenjie
 * @date 2024-02-29 11:13:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/sp/audit")
@Tag(description = "AuditWeb", name = "审批-全部流程-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SpAuditWebController {
    @Resource
    private SpAuditResultService auditResultService;

    /**
     * 全流程状态列表
     */
    @Operation(summary = "全流程状态列表", description = "全流程状态列表")
    @GetMapping("/all/status")
    public R<List<EnumsTypeResultDTO>> allStatus() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(AllAuditActionStatusEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getStatus()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 复杂流程状态列表
     */
    @Operation(summary = "复杂流程状态列表", description = "复杂流程状态列表")
    @GetMapping("/complex/status")
    public R<List<EnumsTypeResultDTO>> complexStatus() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(ComplexAuditActionStatusEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getStatus()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 普通流程状态列表
     */
    @Operation(summary = "普通流程状态列表", description = "普通流程状态列表")
    @GetMapping("/normal/status")
    public R<List<EnumsTypeResultDTO>> normalStatus() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(NormalAuditActionStatusEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getStatus()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 简洁流程状态列表
     */
    @Operation(summary = "简洁流程状态列表", description = "简洁流程状态列表")
    @GetMapping("/simple/status")
    public R<List<EnumsTypeResultDTO>> simpleStatus() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(SimpleAuditActionStatusEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getStatus()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 简要流程状态列表
     */
    @Operation(summary = "简要流程状态列表", description = "简要流程状态列表")
    @GetMapping("/brief/status")
    public R<List<EnumsTypeResultDTO>> briefStatus() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(BriefAuditActionStatusEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getStatus()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 流程审核详情列表
     *
     * @param dto 矫正对象编号
     * @return R
     */
    @Operation(summary = "流程审核详情列表", description = "流程审核详情列表")
    @GetMapping("/list")
    public R<List<SpAuditResultDTO>> detailList(@Valid @ParameterObject SpAuditResultQueryDTO dto) {
        return R.ok(auditResultService.detailList(dto));
    }
}